import 'package:flutter/foundation.dart';

class EqInfo {
  static const int MODE_STANDARD = 0;
  static const int MODE_ROCK = 1;
  static const int MODE_POPULAR = 2;
  static const int MODE_CLASSICAL = 3;
  static const int MODE_JAZZ = 4;
  static const int MODE_COUNTRY = 5;
  static const int MODE_CUSTOM = 6;

  // 假设 DEFAULT_EQ_FREQS 是固定数组，长度为 10
  static const List<int> DEFAULT_EQ_FREQS = [60, 150, 400, 1000, 2400, 6000, 10000, 12000, 14000, 16000];

  int mode;
  List<int> value; // byte[] 在 Dart 中可用 int list 表示
  List<int> freqs;
  bool dynamicValue;
  int count;

  EqInfo({
    this.mode = MODE_STANDARD,
    List<int>? value,
    List<int>? freqs,
    this.dynamicValue = false,
  })  : value = List<int>.filled(10, 0),
        freqs = freqs ?? List.from(DEFAULT_EQ_FREQS),
        count = (freqs ?? DEFAULT_EQ_FREQS).length {
    if (value != null) {
      this.value = List<int>.from(value);
    }
  }

  /// 拷贝构造函数
  EqInfo copy() {
    return EqInfo(
      mode: mode,
      value: List<int>.from(value),
      freqs: List<int>.from(freqs),
      dynamicValue: dynamicValue,
    )..count = count;
  }

  @override
  String toString() {
    final valueStr = value.map((b) => b.toRadixString(16).padLeft(2, '0')).join(' ');
    return 'EqInfo{mode=$mode, isNew=$dynamic, value=[$valueStr], freqs=$freqs}';
  }

  /// 可选：序列化与反序列化方法（类似 Parcelable）
  factory EqInfo.fromJson(Map<String, dynamic> json) {
    print("EqInfo.fromJson: mode ${json['mode'].runtimeType.toString()}");
    print("EqInfo.fromJson: value ${json['value'].runtimeType.toString()}");
    print("EqInfo.fromJson: freqs ${json['freqs'].runtimeType.toString()}");
    print("EqInfo.fromJson: dynamic ${json['dynamic'].runtimeType.toString()}");
    print("EqInfo.fromJson: count ${json['count'].runtimeType.toString()}");
    return EqInfo(
      mode: json['mode'] ?? MODE_STANDARD,
      value: List<int>.from(json['value'] ?? List.filled(10, 0)),
      freqs: List<int>.from(json['freqs'] ?? DEFAULT_EQ_FREQS),
      dynamicValue: json['dynamic'] ?? false,

    )..count = json['count'] ?? DEFAULT_EQ_FREQS.length;
  }

  Map<String, dynamic> toJson() {
    return {
      'mode': mode,
      'value': value,
      'freqs': freqs,
      'dynamic': dynamicValue,
      'count': count,
    };
  }
}
